<link href="/statics/js/jquery-ui/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="/statics/js/jquery-ui/jquery-ui.js"></script>
<script src="/statics/js/timepicker.js"></script>
<script>
$(function(){
	var slength = 140
	$("#weibo_body").keydown(function(){
		var curLength=$(this).val().length;
		if(curLength >= slength){
			var num = $(this).val().substr(0,slength);
			$(this).val(num);
		   // alert("超过字数限制，多出的字将被截断！" );
		}
		
		$("#num_ps").html(slength - $(this).val().length);
	})
	
	$(".huati").toggle(function(){
		$(".definite").find('input[name=timing]').val('1');
		$(".definite").slideDown(300,function(){
			$(".pic_balck").css('top',parseInt($(".pic_balck").css('top').replace('px',''))+parseInt($(this).height()))
		});
		$(".save_go > ul").html('');
		$.getJSON('/account/lists/',function(data){
			$(data).each(function(key,val){
				$(".save_go > ul").append('<li><img src="'+val['face']+'" align="absmiddle"/><br>'+val['name']+'<input type="checkbox" checked value="'+val['id']+'" name="userid[]" /> </li>');
			})
			$(".save_go > ul > li").click(function(){
				if ($(this).children('input').attr('checked') == true)
				{
					$(this).children('input').attr('checked',false);
					$(this).children('img').css('background','none');
				}
				else
				{
					$(this).children('input').attr('checked',true);
					$(this).children('img').css('background','#2b4a78');
				}
			})
			
		})
	},function(){
		$(".definite").find('input[name=timing]').val('0');
		$(".pic_balck").css('top',parseInt($(".pic_balck").css('top').replace('px',''))-parseInt($(".definite").height()))
		$(".definite").slideUp(300);
	})
	
	$("#weibo_save").submit(function(data){
		txt = $(this).find('textarea[name=status]');
		if ($(txt).val()=='')
		{
			alert('什么都没有，您要发什么？');
			$(txt).focus()
			return false;
		}
		$.post($(this).attr('action'),$(this).serialize(),function(data){
			
			
			if (data == '2')
			{
				alert('定时任务创建成功!');
				$(txt).val('');
				$(".pic_balck").empty();
				$("#pic_input").val('');
				return false;
			}
			var data = $(data).hide();
			$(".weibos").prepend(data);
			$(data).slideDown(600);
			$(txt).val('');
			$(".pic_balck").empty();
			$("#pic_input").val('');
		})
		return false;
	})
	
	/* 载入图片上传 */
	$(".weibo_ac .pic").powerFloat({
		eventType: "click",
		target: "/weibo/upload",
		targetMode: "ajax"
	});
	
	 $('input[name=dtime]').datetimepicker();

})
function del_pic(obj)
{
	$.get('/weibo/del_pic/',{file:$(obj).attr('href')},function(data){
		
		if (data == '1')
		{
			$(".pic_balck").empty();
			$("#pic_input").val('');
			$("#weibo_body").val($("#weibo_body").val().replace('分享图片',''));
		}
		
	});
	return false;
}
</script>
<style>
.float_ajax_data{padding:10px;}
.pic_balck{position:absolute;left:77px;top:145px;background:#fff;text-align:center;border:1px #ccc solid;z-index:100}
.pic_balck img{ padding:3px;background:#fff;width:expression(this.width/this.height > 126/96 ? 126 : (this.width*96/this.height));height:expression(this.width/this.height > 126/96 ? (this.width*126/this.height) : 96);max-height:96px;max-width:126px;}

.ui-timepicker-div .ui-widget-header{ margin-bottom: 228px; }
.ui-timepicker-div dl{ text-align: left; }
.ui-timepicker-div dl dt{ height: 25px; }
.ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; }
.ui-timepicker-div td { font-size: 90%; }
</style>
<form id="weibo_save" name="form1" method="post" action="/weibo/info">
<div class="weibo_text" style="position:relative;z-index:99px;">
	<textarea id="weibo_body" name="status" accesskey="u" autocomplete="off" tabindex="1"></textarea>
	<input type="hidden" name="pic" id="pic_input" value=""> 
	<div class="pic_balck"></div> 
	<div class="definite">
		<div class="timing">
			选择时间:<input type="text" name="dtime" value="<?php echo $dtime;?>"/> 或 
			<select name="rand_time">
				<option value="">--随机时间--</option>
				<?php foreach ($rand_time as $key=>$val){?>
				<option value="<?php echo $key;?>"><?php echo $val;?></option>
				<?php }?>
			</select>
			<input type="hidden" value="" name="timing">
		</div>
		<div class="save_go">
			<h2>发布到...</h2>
			<ul></ul>
		</div>
	</div>
	<div class="weibo_fabu">
		<div class="weibo_ac">
			<a href="javascript:" class="face">表情</a>
			<a href="javascript:" class="pic">图片</a>
			<a href="javascript:" class="huati">定时发送</a>
		</div>
		<div class="weibo_ps overflow">
			<input type="submit" value="发送" title="快捷键 Ctrl+Enter" id="fasong" tabindex="2">
			
			<span>还能输入<font id="num_ps">140</font>字</span>
		</div>
	</div>
</div>
</form>